﻿using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using AppFramework.Demo.Dtos;
using AppFramework.DinosaursParkMes.Process.DTO;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Dynamic.Core;
using AppFramework.Version.Dtos;
using AppFramework.Authorization;
using Abp.Authorization;





namespace AppFramework.DinosaursParkMes.Process
{
    /// <summary>
    /// 工艺路线字表的服务
    /// </summary>
    public class CraftProcessAppService : AppFrameworkAppServiceBase, ICraftProcessAppService
    {
        private readonly IRepository<CraftProcessModel> _repository;
        public CraftProcessAppService(IRepository<CraftProcessModel> repository = null)
        {
            _repository = repository;
        }
        /// <summary>
        /// 工艺路线子表添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("CraftProcessAdd")]
        public async Task<int> CraftProcessAdd(CraftProcessDTO dto)
        {
            //CraftProcessModel model = new CraftProcessModel(dto.Serialnumber, dto.Craftcode, dto.Process, dto.Nextprocess, dto.Relation, dto.Keyprocess, dto.Showcolor, dto.Remark,dto.Readinesstime,dto.Waitingtime);
            //CraftProcessModel craftProcessModel = await _repository.InsertAsync(model);
            _repository.InsertAsync(ObjectMapper.Map<CraftProcessModel>(dto));
            return 1;

        }
        /// <summary>
        /// 工艺路线子表显示
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet("GetCraftprocessShow")]
        public async Task<dynamic> GetCraftprocessShow()
        {
            //var filteredAbpModels = _repository.GetAll();
                      
            //var pagedAndFilteredAbpVersions = filteredAbpModels
            //    .OrderBy(input.Sorting ?? "id asc")
            //    .PageBy(input);
            //var totalCount = await filteredAbpModels.CountAsync();
            //var dbList = await pagedAndFilteredAbpVersions.ToListAsync();
            //var results = ObjectMapper.Map<List<CraftProcessDTO>>(dbList);
            //return new PagedResultDto<CraftProcessDTO>(totalCount, results);
            var list = _repository.GetAllList();
            return list;

        }
    }
}
